<%@ page language="java" contentType="text/html;charset=UTF-8" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested"%>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack"%>

<chiptrack:checkLogon sourcePage="purchaseOrders.do"/>
<%@ page import="com.scalar.chiptrack.utils.ConfigManager,
                 com.scalar.chiptrack.users.Functionality,
                 com.scalar.chiptrack.users.User,
                 java.util.ArrayList"%>
<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel=stylesheet>

<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY bgColor="#ffffff" leftMargin=0 topMargin=0 marginheight="0" marginwidth="0" onUnload="closeWindow()">

<SCRIPT language="JavaScript">
    function addRow( rowId )
    {
        var row = document.getElementById(rowId);
        var table = row.parentElement;
        var newRow = table.insertRow(row.rowIndex);
        var td = newRow.insertCell();
        td.width = "62";
        td.innerHTML="&nbsp;";
        td = newRow.insertCell();
        td.width="128";
        td.innerHTML = '<input type=text name="packageType" class=txfield size="20" maxlength="50" />';
        td = newRow.insertCell();
    }

    function save()
    {
        var errors	= "";
		var li      = document.getElementById( "message" );
		li.style.visibility = "visible";

        if( typeof document.processTypeSetupForm.packageType != 'undefined' )
        {
            if( typeof document.processTypeSetupForm.packageType.length != 'undefined' )
            {
                var noOfPackageType = document.processTypeSetupForm.packageType.length;
                for( var k = 0; k < noOfPackageType; k++ )
                {
                    var name  = document.processTypeSetupForm.packageType[k].value;
                    document.processTypeSetupForm.packageType[k].value = name;

                   if( name != '' )
                    {
                        for( var i = 0; i < k; i++ )
                        {
                            var lastName = document.processTypeSetupForm.packageType[i].value;
                            lastName = lastName;
                            if( name.toUpperCase() == lastName.toUpperCase() )
                            {
                                errors = errors+"<li> Package name already exists please select another name";
                                li.innerHTML = errors;
                                document.processTypeSetupForm.packageType[k].focus();
                                return ;
                            }
                        }
                    }
                }
            }
            else
            {
                if( document.processTypeSetupForm.packageType.value == '')
                {
                     errors = errors+"<li> Please enter the Package name";
                     li.innerHTML = errors;
                    return false;
                }
            }
        }

        if( typeof document.processTypeSetupForm.packageType != 'undefined' )
        {
            if( typeof document.processTypeSetupForm.packageType.length != 'undefined' )
            {
                var noOfPackageType = document.processTypeSetupForm.packageType.length;
                for( var k = 0; k < noOfPackageType; k++ )
                {
                    document.processTypeSetupForm.packageType[k].disabled = false;
                }
            }
            else
            {
                document.processTypeSetupForm.packageType.disabled = false;
            }
        }

        document.processTypeSetupForm.action='<%=chipTracContext%>/processTypeSetup.do?action=savePackageType' ;
        document.processTypeSetupForm.submit();
    }

    var closeFlag = false;
    function closeWindow()
    {
        if ( !closeFlag )
        {
            closeFlag = true;
            opener.parent.refresh();
        }
        window.close();
    }

</SCRIPT>

<html:form name="processTypeSetupForm"  type="com.scalar.chiptrack.operations.processtypesetup.forms.ProcessTypeSetupForm" action="/processTypeSetup.do">

<TABLE cellSpacing=0 cellPadding=0 width="100%" border="0">
    <TBODY>
    <TR>
	    <TD width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'></TD>
        <TD bgcolor="#ffffff">
        <IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
        <TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
        <TD valign="top" width="100%">
        <IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
        <BR>
        <!-- from here your body starts -->
        <TABLE border="0">
            <TR>
            <TD>&nbsp;</TD>
            <TD colspan =2>
                    <font class='NArialS'><font color='orange'><b>
						<li>To add new Package, click on [+]
						</b>
					</font>
                </TD>
            </TR>
            <tr>
                <td colspan=3><font class="NArialL"><font align=left color="FF0000" id=message ></font></td>
            </tr>
            <TR><TD colspan =3 class="NArialL"><chiptrack:messages type="info" styleClass="NArialL" /></TD></TR>
            <tr><td colspan=3><chiptrack:info styleClass="NArialL"/></td></tr>
			<tr><td colspan=3><chiptrack:errors styleClass="NArialL"/></td></tr>
            <TR>
                <TD colspan="3" bgColor="#993333" width="263" height="16"><FONT class="NArialL" style="color:#ffffff" id="fieldLabel">&nbsp;Add New Package:</FONT></TD>
            </TR>
            <%
                int colno = 0;
                ArrayList packList = (ArrayList)request.getAttribute("packageTypeList");
            %>
            <% for( int i=0; i < packList.size(); i++ ){ %>
            <TR>
                <TD width="62">&nbsp;</TD>
                <TD width="128">
                    <input type=text name="packageType"  value = "<%=packList.get(i)%>"class=txfield size="20" maxlength="50" disabled = "true" />
                </TD>
                <TD><% if ( colno == 0 ) { %> <a href="javascript:addRow('rowId1');"><img border=0 src='<%=chipTracContext%>/jsp/includes/images/add.jpg' height='15' width='20' align=center onmouseover="window.status='Click here to add row';return true" title="Click here to add row" onmouseout="window.status='';return true" ></a> <% } %></TD>
               <% colno++;%>
            </TR>
            <%}if( packList.size() == 0 ){%>
             <TR>
                <TD width="62">&nbsp;</TD>
                <TD width="128">
                    <input type=text name="packageType" class=txfield size="20" maxlength="50" />
                </TD>
                <TD><a href="javascript:addRow('rowId1');"><img border=0 src='<%=chipTracContext%>/jsp/includes/images/add.jpg' height='15' width='20' align=center onmouseover="window.status='Click here to add row';return true" title="Click here to add row" onmouseout="window.status='';return true" ></a></TD>
            </TR>
            <%}%>
            <TR  id="rowId1"><TD colspan="3" ></TD></TR>
            <TR>
                <TD width="62">&nbsp;</TD>
                <TD colspan="2" width="195">&nbsp;</TD>
            </TR>
            <TR>
                <TD width="62">&nbsp;</TD>
                <TD align="center">
                    <a href="javascript:save();"><IMG onmouseover="window.status='Click here to Save Package Types';return true" title="Click here to Save Package Types" onmouseout="window.status='';return true" height=17 src="<%=chipTracContext%>/jsp/includes/images/save.gif"  width=53 border=0></a>
                    <a href="javascript:document.processTypeSetupForm.reset();"><IMG onmouseover="window.status='Click to Reset';return true" title="Click here to Reset" onmouseout="window.status='';return true" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" border=0 width="53" height="17"></a>
                </TD>
                <TD colspan="5">&nbsp;</TD>
            </TR>
            <TR>
                <TD colspan="6" align="center">
                    <a href="javascript:closeWindow();"  onMouseOver="window.status='Click here to close this window';return true" title='Click here to close this window'><font class='NArialL'><b>[Close this window]</b></font></a>
                </TD>
            </TR>
        </TABLE>
</html:form>
    </TD>
<!-- till here -->
  </TR>
  </TBODY>
</TABLE>
</BODY>
</HTML>


